package com.zcxx.cotton.pick.task;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.config.ApiConfig;
import com.ruoyi.common.config.TaskConfig;
import com.ruoyi.common.utils.http.SendUtils;
import com.zcxx.cotton.base.domain.PubPickerDevice;
import com.zcxx.cotton.base.service.IPubPickerDeviceService;


import com.zcxx.cotton.pick.domain.*;
import com.zcxx.cotton.pick.mapper.PickMapElementMapper;
import com.zcxx.cotton.pick.service.*;

import com.zcxx.cotton.pick.util.MapUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
import java.util.stream.Collectors;


/**
 * @author 吴璇璇
 * @title: PickDeviceTask
 * @projectName ruoyi
 * @description: TODO
 * @date 2025/7/18 14:21
 */
@Component("PickDeviceTask")
public class PickDeviceTask {

    protected final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IPubPickerDeviceService mesDeviceService;

    @Autowired
    private PickMapElementMapper pickMapElementMapper;

    //先从接口里拉过来坐标信息--保存
    @Autowired
    private IPickMapInfoFirstbuService mapInfoFirstbuService;

    @Autowired
    private IPickInfoFirstbuService pickInfoFirstbuService;

    @Autowired
    private IPickMapInfoService pickMapInfoService;

    @Autowired
    private IPickInfoService pickInfoService;

    @Autowired
    private IPickMapElementService pickMapElementService;


    @Autowired
    private ApiConfig apiConfig;

    @Autowired
    private SendUtils sendUtils;


    /**
     * 每1分钟执行一次,从平台获取采棉机列表信息(0 0/15 * * * ?)
     * 15分钟一次
     */
    //@Scheduled(cron = "0 0/1 * * * ?")
    public void getPickerDevice() {
        try {
            if (!TaskConfig.isFlag()) {
                return;
            }
            String URL = apiConfig.getUrl() + "/api/getPickerList";
            JSONObject object = new JSONObject();
            object.put("deptId", apiConfig.getDeptId());
            String s = sendUtils.sendPost(URL, object);
            JSONObject parse = JSONObject.parse(s);
            JSONArray data = parse.getJSONArray("data");
            // JSONArray转List
            List<PubPickerDevice> list = data.toJavaList(PubPickerDevice.class);
            mesDeviceService.saveOrUpdateBatch(list);
        } catch (Exception e) {
            log.error("拉去采棉机信息失败---" + e.getLocalizedMessage());
        }
    }


    /**
     * 每隔1小时执行一次,拉去接口返回的采棉机坐标信息
     */
    //@Scheduled(cron = "0 0 */1 * * ?")
    //@Scheduled(cron = "0 0/1 * * * ?")
    public void getPickMapList() {
        if (!TaskConfig.isFlag()) {
            return;
        }
        LocalDate yesterday = LocalDate.now().minusDays(1);
        LocalDate tomorrow = LocalDate.now().plusDays(1);

        // 格式化输出
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = yesterday.format(formatter);
        String tomorrowDate = tomorrow.format(formatter);
        String URL = apiConfig.getUrl() + "/api/getPickMapList";
        //查询全部采棉机
        List<PubPickerDevice> list = mesDeviceService.list();
        for (PubPickerDevice pubPickerDevice : list) { //查询每个采棉机的坐标
            try {
                JSONObject object = new JSONObject();
                object.put("deviceMainCode", pubPickerDevice.getPickerCode());
                object.put("startTime", formattedDate+" 23:00:00");
                object.put("endTime", tomorrowDate+" 23:59:59");
                String s = sendUtils.sendPost(URL, object);
                JSONObject response = JSONObject.parse(s);
                if (response != null && response.containsKey("data") && response.getJSONArray("data") != null) {
                    JSONArray data = response.getJSONArray("data");
                    List<PickMapInfo> pickMapInfos = data.toJavaList(PickMapInfo.class);
                    pickMapInfos.forEach(item -> {
                        item.setDeviceMainCode(pubPickerDevice.getPickerCode());
                    });
                    pickMapInfoService.saveOrUpdateBatch(pickMapInfos);
                }
            } catch (Exception e) {
                log.error("拉去坐标信息失败---" + e.getLocalizedMessage());
            }
        }
    }


    /**
     * 每2小时执行一次,筛选利华的坐标信息保存到pick_map_info
     */
    //@Scheduled(cron = "0 0/1 * * * ?")
 /*   public void getPickerMapSave() {
        if(!TaskConfig.isFlag()){
            return;
        }
        //获取全部的坐标信息数据
        LambdaQueryWrapper<PickMapInfoFirstbu> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.select(PickMapInfoFirstbu::getMapInfoId,PickMapInfoFirstbu::getDeviceMainCode,PickMapInfoFirstbu::getLongitude,PickMapInfoFirstbu::getLatitude,PickMapInfoFirstbu::getSpeed,PickMapInfoFirstbu::getDirection,PickMapInfoFirstbu::getCreateTime);
        List<PickMapInfoFirstbu> listA = mapInfoFirstbuService.list(lambdaQueryWrapper);
        //获取利华的地块信息数据
        List<PickMapElement> listB = pickMapElementMapper.selectAllElementList(apiConfig.getDeptId());
        //判断listA的坐标是否属于listB
        //处理过的数据
        List<Long> dealList=new ArrayList<>();
        for (PickMapInfoFirstbu pickMapInfoFirstbu:listA){
            for (PickMapElement pickMapElement:listB){
                String detail = pickMapElement.getDetail();
                //先处理闭环
                String bihuan=SendUtils.areFirstAndLastTwoEqual(detail);
                //在处理格式
                String result = SendUtils.joinSpecialSimple(bihuan);
                //交换每组经纬度的位置
                String jiaohuan=SendUtils.swapPairs(result);
                String longitude = pickMapInfoFirstbu.getLongitude();
                String latitude = pickMapInfoFirstbu.getLatitude();
                //判断经纬度是不是在地里
                try {
                    boolean fanhui=pickMapElementMapper.getTrueOrFalse(longitude,latitude,jiaohuan);
                    if(fanhui==true){
                        PickMapInfo pickMapInfo=new PickMapInfo();
                        BeanUtils.copyProperties(pickMapInfoFirstbu,pickMapInfo);
                        pickMapInfo.setId(pickMapElement.getId());
                        pickMapInfoService.saveOrUpdate(pickMapInfo);
                        break;
                    }
                }catch (Exception e) {
                    System.err.println("General error: " + e.getMessage());
                    e.printStackTrace();
                }
            }
            dealList.add(pickMapInfoFirstbu.getMapInfoId());
        }
        LambdaQueryWrapper<PickMapInfoFirstbu> lambdaQueryWrapper1=new LambdaQueryWrapper<>();
        lambdaQueryWrapper1.in(PickMapInfoFirstbu::getMapInfoId,dealList);
        mapInfoFirstbuService.remove(lambdaQueryWrapper1);
    }*/


    /**
     * 每隔1小时执行一次,拉去接口返回的采摘信息（从平台获取棉包列表信息接口）
     */
    //@Scheduled(cron = "0 0 */1 * * ?")
    //@Scheduled(cron = "0 0/1 * * * ?")
    public void getPickInfoList() {
        try {
            if (!TaskConfig.isFlag()) {
                return;
            }
            LocalDate yesterday = LocalDate.now().minusDays(1);
           // LocalDate  taday= LocalDate.now();
            LocalDate tomorrow = LocalDate.now().plusDays(1);

            // 格式化输出
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            String formattedDate = yesterday.format(formatter);
            String tomorrowDate = tomorrow.format(formatter);
            String URL = apiConfig.getUrl() + "/api/getPickInfoList";
            //查询全部采棉机
            List<PubPickerDevice> list = mesDeviceService.list();
            for (PubPickerDevice pubPickerDevice : list) { //查询每个采棉机的坐标
                JSONObject object = new JSONObject();
                object.put("deviceMainCode", pubPickerDevice.getPickerCode());
                object.put("startTime", formattedDate+" 23:00:00");
                object.put("endTime",  tomorrowDate+" 23:59:59");
                String s = sendUtils.sendPost(URL, object);
                JSONObject parse = JSONObject.parse(s);
                JSONArray data = parse.getJSONArray("data");
                List<PickInfoFirstbu> firstbus = data.toJavaList(PickInfoFirstbu.class);
                pickInfoFirstbuService.saveOrUpdateBatch(firstbus);
            }
        } catch (Exception e) {
            log.error("拉去采摘信息失败---" + e.getLocalizedMessage());
        }
    }


    /**
     * 每3小时执行一次,筛选利华的坐标信息保存到pick_info
     */
    //@Scheduled(cron = "0 0/1 * * * ?")
    public void getPickerInfoSave() {
        try {
            if (!TaskConfig.isFlag()) {
                return;
            }
            //获取全部的采摘信息数据
            List<PickInfoFirstbu> listA = pickInfoFirstbuService.list();
            //获取利华的地块信息数据
            List<PickMapElement> listB = pickMapElementMapper.selectAllElementList(apiConfig.getDeptId());
            List<Long> list = listA.stream().map(PickInfoFirstbu::getPickInfoId).collect(Collectors.toList());
            //判断listA的坐标是否属于listB
            for (PickInfoFirstbu pickInfoFirstbu : listA) {
                for (PickMapElement pickMapElement : listB) {
                    String detail = pickMapElement.getDetail();
                    //先处理闭环
                    String bihuan = SendUtils.areFirstAndLastTwoEqual(detail);
                    String result = SendUtils.joinSpecialSimple(bihuan);
                    //交换每组经纬度的位置
                    String jiaohuan = SendUtils.swapPairs(result);
                    String longitude = pickInfoFirstbu.getLongitude();
                    String latitude = pickInfoFirstbu.getLatitude();
                    //判断经纬度是不是在地里
                    try {
                        boolean fanhui = pickMapElementMapper.getTrueOrFalse(longitude, latitude, jiaohuan);
                        if (fanhui == true) {
                            PickInfo pickInfo = new PickInfo();
                            BeanUtils.copyProperties(pickInfoFirstbu, pickInfo);
                            pickInfo.setId(pickMapElement.getId());
                            pickInfoService.saveOrUpdate(pickInfo);
                            //说明这个地里有棉包
                            pickMapElement.setMianbao("1");
                            pickMapElementMapper.updateMianbao(pickMapElement);
                            break;
                        }
                    } catch (Exception e) {
                        System.err.println("General error: " + e.getMessage());
                        e.printStackTrace();
                    }
                }
            }
            LambdaQueryWrapper<PickInfoFirstbu> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.in(PickInfoFirstbu::getPickInfoId, list);
            pickInfoFirstbuService.remove(lambdaQueryWrapper);
        } catch (Exception e) {
            log.error("筛选利华的坐标信息保存到pick_info失败---" + e.getLocalizedMessage());
        }
    }


    //////////////////////////////////////////////以下是优化版本(备用)///////////////////////////////////////////////////////////////////////////////

    //从接口获取坐标信息
    public void getPickMapList1() {
        if (!TaskConfig.isFlag()) {
            return;
        }
        String URL = apiConfig.getUrl() + "/api/getPickMapList";
        List<PubPickerDevice> devices = mesDeviceService.list();
        // 使用线程安全的列表收集所有数据
        List<PickMapInfo> allPickMapInfos = Collections.synchronizedList(new ArrayList<>());
        devices.parallelStream().forEach(device -> {
            try {
                JSONObject requestBody = new JSONObject();
                requestBody.put("deviceMainCode", device.getPickerCode());
                requestBody.put("startTime", apiConfig.getStartTime());
                requestBody.put("endTime", apiConfig.getEndTime());

                String response = sendUtils.sendPost(URL, requestBody);
                JSONObject responseJson = JSONObject.parse(response);

                if (isValidResponse(responseJson)) {
                    JSONArray dataArray = responseJson.getJSONArray("data");
                    List<PickMapInfo> devicePickMapInfos = dataArray.toJavaList(PickMapInfo.class);
                    if (!devicePickMapInfos.isEmpty()) {
                        devicePickMapInfos.forEach(item -> item.setDeviceMainCode(device.getPickerCode()));
                        synchronized (allPickMapInfos) {
                            allPickMapInfos.addAll(devicePickMapInfos);
                        }
                        log.info("设备 {} 获取到 {} 条坐标数据", device.getPickerCode(), devicePickMapInfos.size());
                    }
                }
            } catch (Exception e) {
                log.error("处理设备 {} 数据时发生错误: {}", device.getPickerCode(), e.getMessage());
            }
        });

        // 一次性批量保存所有数据
        if (!allPickMapInfos.isEmpty()) {
            savePickMapInfosInBatches(allPickMapInfos);
        } else {
            log.info("未获取到任何采棉机坐标数据");
        }
    }

    private boolean isValidResponse(JSONObject response) {
        return response != null && response.containsKey("data") && response.getJSONArray("data") != null;
    }

    private void savePickMapInfosInBatches(List<PickMapInfo> pickMapInfos) {
        int batchSize = 1000; // 每批处理1000条数据
        int totalSize = pickMapInfos.size();
        for (int i = 0; i < totalSize; i += batchSize) {
            int end = Math.min(i + batchSize, totalSize);
            List<PickMapInfo> batch = pickMapInfos.subList(i, end);
            try {
                boolean success = pickMapInfoService.saveOrUpdateBatch(batch);
                if (success) {
                    log.info("成功保存第 {} 批数据，共 {} 条记录", (i / batchSize + 1), batch.size());
                } else {
                    log.error("第 {} 批数据保存失败", (i / batchSize + 1));
                }
            } catch (Exception e) {
                log.error("保存第 {} 批数据时发生错误: {}", (i / batchSize + 1), e.getMessage());
                // 可以在这里添加重试逻辑
                retrySaveBatch(batch, 3); // 重试3次
            }
        }
        log.info("总共保存了 {} 条采棉机坐标数据", totalSize);
    }

    private void retrySaveBatch(List<PickMapInfo> batch, int maxRetries) {
        for (int retry = 1; retry <= maxRetries; retry++) {
            try {
                Thread.sleep(1000 * retry); // 延迟重试
                boolean success = pickMapInfoService.saveOrUpdateBatch(batch);
                if (success) {
                    log.info("重试第 {} 次成功", retry);
                    return;
                }
            } catch (Exception e) {
                log.warn("第 {} 次重试失败: {}", retry, e.getMessage());
            }
        }
        log.error("经过 {} 次重试后仍然失败", maxRetries);
    }


    /**
     * 筛选利华的坐标信息保存到pick_info
     */
    //@Scheduled(cron = "0 0/1 * * * ?")
    public void getPickerInfoSave1() {
        if (!TaskConfig.isFlag()) {
            return;
        }

        //获取全部的采摘信息数据
        List<PickInfoFirstbu> listA = pickInfoFirstbuService.list();
        //获取利华的地块信息数据
        List<PickMapElement> listB = pickMapElementMapper.selectAllElementList(apiConfig.getDeptId());

        // 预处理--获取地块id和处理过的坐标
        Map<Long, String> processedElements = preprocessElements(listB);
        Map<Long, PickMapElement> elementMap = listB.stream()
                .collect(Collectors.toMap(PickMapElement::getId, Function.identity()));

        // 线程安全集合
        List<Long> processedIds = listA.stream().map(PickInfoFirstbu::getPickInfoId).collect(Collectors.toList());
        List<PickInfo> pickInfosToSave = Collections.synchronizedList(new ArrayList<>());
        Set<Long> elementsToUpdate = Collections.synchronizedSet(new HashSet<>());

        // 创建线程池
        int threadCount = Runtime.getRuntime().availableProcessors();
        ExecutorService executor = Executors.newFixedThreadPool(threadCount);

        // 创建任务列表
        List<Callable<Void>> tasks = new ArrayList<>();

        for (PickInfoFirstbu pickInfoFirstbu : listA) {
            tasks.add(() -> {
                processPickInfo(pickInfoFirstbu, processedElements,
                        pickInfosToSave, elementsToUpdate);
                return null;
            });
        }

        try {
            // 执行所有任务
            List<Future<Void>> futures = executor.invokeAll(tasks);

            // 等待所有任务完成
            for (Future<Void> future : futures) {
                future.get();
            }
        } catch (InterruptedException | ExecutionException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException("多线程执行失败", e);
        } finally {
            executor.shutdown();
        }

        // 批量操作（同上）
        batchOperations(pickInfosToSave, elementsToUpdate, elementMap, processedIds);
    }


    private void processPickInfo(PickInfoFirstbu pickInfoFirstbu,
                                 Map<Long, String> processedElements,
                                 List<PickInfo> pickInfosToSave,
                                 Set<Long> elementsToUpdate
    ) {
        String longitude = pickInfoFirstbu.getLongitude();
        String latitude = pickInfoFirstbu.getLatitude();

        for (Map.Entry<Long, String> entry : processedElements.entrySet()) {
            try {
                boolean fanhui = pickMapElementMapper.getTrueOrFalse(longitude, latitude, entry.getValue());
                if (fanhui) {
                    PickInfo pickInfo = new PickInfo();
                    BeanUtils.copyProperties(pickInfoFirstbu, pickInfo);
                    pickInfo.setId(entry.getKey());

                    synchronized (pickInfosToSave) {
                        pickInfosToSave.add(pickInfo);
                    }

                    synchronized (elementsToUpdate) {
                        elementsToUpdate.add(entry.getKey());
                    }
                    break;
                }
            } catch (Exception e) {
                log.error("Error processing point: " + e.getMessage());
            }
        }
    }

    // 预处理地块数据
    private Map<Long, String> preprocessElements(List<PickMapElement> listB) {
        Map<Long, String> result = new HashMap<>();
        for (PickMapElement element : listB) {
            String detail = element.getDetail();
            String bihuan = SendUtils.areFirstAndLastTwoEqual(detail);
            String resultStr = SendUtils.joinSpecialSimple(bihuan);
            String jiaohuan = SendUtils.swapPairs(resultStr);
            result.put(element.getId(), jiaohuan);
        }
        return result;
    }

    private void batchOperations(List<PickInfo> pickInfosToSave,
                                 Set<Long> elementsToUpdate,
                                 Map<Long, PickMapElement> elementMap,
                                 List<Long> processedIds) {

        // 1. 批量保存PickInfo信息
        if (!pickInfosToSave.isEmpty()) {
            try {
                // 使用MyBatis Plus的saveOrUpdateBatch方法
                boolean saveResult = pickInfoService.saveOrUpdateBatch(pickInfosToSave);
                if (saveResult) {
                    log.info("成功批量保存 " + pickInfosToSave.size() + " 条PickInfo记录");
                } else {
                    log.error("批量保存PickInfo记录失败");
                }
            } catch (Exception e) {
                log.error("批量保存PickInfo时发生错误: " + e.getMessage());
                // 可以在这里添加重试机制或分批保存的逻辑
                batchSaveWithRetry(pickInfosToSave);
            }
        }

        // 2. 批量更新地块的棉包状态
        if (!elementsToUpdate.isEmpty()) {
            try {
                // 创建需要更新的地块列表
                List<PickMapElement> elementsToUpdateList = elementsToUpdate.stream()
                        .map(elementMap::get)
                        .filter(Objects::nonNull)
                        .peek(element -> element.setMianbao("1"))
                        .collect(Collectors.toList());

                if (!elementsToUpdateList.isEmpty()) {
                    // 批量更新（需要实现批量更新方法）
                    updateElementsMianbaoBatch(elementsToUpdateList);
                    log.info("成功更新 " + elementsToUpdateList.size() + " 个地块的棉包状态");
                }
            } catch (Exception e) {
                log.error("批量更新地块状态时发生错误: " + e.getMessage());
                //  fallback: 逐个更新
                updateElementsOneByOne(elementsToUpdate, elementMap);
            }
        }

        // 3. 批量删除已处理的PickInfoFirstbu记录
        if (!processedIds.isEmpty()) {
            try {
                // 去重处理
                List<Long> distinctProcessedIds = processedIds.stream()
                        .distinct()
                        .collect(Collectors.toList());

                LambdaQueryWrapper<PickInfoFirstbu> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.in(PickInfoFirstbu::getPickInfoId, distinctProcessedIds);

                boolean removeResult = pickInfoFirstbuService.remove(lambdaQueryWrapper);
                if (removeResult) {
                    log.info("成功删除 " + distinctProcessedIds.size() + " 条已处理的PickInfoFirstbu记录");
                } else {
                    log.error("删除PickInfoFirstbu记录失败");
                }
            } catch (Exception e) {
                log.error("批量删除记录时发生错误: " + e.getMessage());
                // fallback: 分批删除
                batchDeleteWithChunking(processedIds);
            }
        }
    }


    /**
     * 分批保存重试机制
     */
    private void batchSaveWithRetry(List<PickInfo> pickInfosToSave) {
        int batchSize = 100; // 每批处理100条
        int maxRetries = 3;

        for (int i = 0; i < pickInfosToSave.size(); i += batchSize) {
            int end = Math.min(i + batchSize, pickInfosToSave.size());
            List<PickInfo> batch = pickInfosToSave.subList(i, end);

            for (int retry = 0; retry < maxRetries; retry++) {
                try {
                    boolean success = pickInfoService.saveOrUpdateBatch(batch);
                    if (success) {
                        log.info("第 " + (i / batchSize + 1) + " 批数据保存成功");
                        break;
                    }
                } catch (Exception e) {
                    if (retry == maxRetries - 1) {
                        log.error("第 " + (i / batchSize + 1) + " 批数据保存失败，已达到最大重试次数");
                    }
                }
            }
        }
    }

    /**
     * 批量更新地块棉包状态
     */
    private void updateElementsMianbaoBatch(List<PickMapElement> elementsToUpdate) {
        // 方法1: 使用MyBatis Plus的批量更新（需要配置）
        // pickMapElementService.updateBatchById(elementsToUpdate);

        // 方法2: 使用自定义的批量更新SQL
        if (elementsToUpdate.size() == 1) {
            // 单个更新
            pickMapElementMapper.updateMianbao(elementsToUpdate.get(0));
        } else {
            // 批量更新（需要实现批量更新方法）
            pickMapElementMapper.updateMianbaoBatch(elementsToUpdate);
        }
    }

    /**
     * 逐个更新地块状态（fallback方法）
     */
    private void updateElementsOneByOne(Set<Long> elementsToUpdate, Map<Long, PickMapElement> elementMap) {
        for (Long elementId : elementsToUpdate) {
            try {
                PickMapElement element = elementMap.get(elementId);
                if (element != null) {
                    element.setMianbao("1");
                    pickMapElementMapper.updateMianbao(element);
                }
            } catch (Exception e) {
                log.error("更新地块 " + elementId + " 状态失败: " + e.getMessage());
            }
        }
    }


    /**
     * 分批删除处理
     */
    private void batchDeleteWithChunking(List<Long> processedIds) {
        int chunkSize = 500; // 每批删除500条
        List<Long> distinctIds = processedIds.stream().distinct().collect(Collectors.toList());

        for (int i = 0; i < distinctIds.size(); i += chunkSize) {
            int end = Math.min(i + chunkSize, distinctIds.size());
            List<Long> chunk = distinctIds.subList(i, end);

            try {
                LambdaQueryWrapper<PickInfoFirstbu> wrapper = new LambdaQueryWrapper<>();
                wrapper.in(PickInfoFirstbu::getPickInfoId, chunk);
                pickInfoFirstbuService.remove(wrapper);
                log.info("成功删除第 " + (i / chunkSize + 1) + " 批记录，共 " + chunk.size() + " 条");
            } catch (Exception e) {
                log.error("删除第 " + (i / chunkSize + 1) + " 批记录失败: " + e.getMessage());
            }
        }
    }


    /**
     * 测试建表的语句，暂时用不到
     */
    //@Scheduled(cron = "0 0/1 * * * ?")
    public void createTable() {
        if (!TaskConfig.isFlag()) {
            return;
        }
        String tbName = "pick_map_info";
        tbName = "pick_map_info_" + "4000000531" + "_" + "2024";
        System.out.println(tbName);
        try {
            pickMapInfoService.createTable(tbName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
